package cn.bdqn.page2;

import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * 本月账单查询,这个类一直报空指针异常，不知道是为啥呀！！！！
 */
public class BillSearch {
	// 因为所有的方法都需要DOM树
	static Document document = null;
	static Element root = null;

	// 本月账单查询
	public void billSearch(String phone) throws DocumentException,
			NumberFormatException {
		System.out.println("**********本月账单查询***********");
		System.out.println("您的卡号：" + phone + "\n当月账单：");
		SAXReader reader = new SAXReader();
		document = reader.read("UserMessage.xml");
		root = (Element) document.getRootElement();
		Iterator itUser = root.elementIterator();
		while (itUser.hasNext()) {
			Element user = (Element) itUser.next();
			// if (phone.equals(user.attributeValue("id"))) {
			System.out.println("套餐资费：" + user.attributeValue("money"));
			// 合计
			double recharge = Double.valueOf(Double.parseDouble(user
					.attributeValue("recharge")));
			double balance = Double.valueOf(Double.parseDouble(user
					.attributeValue("balance")));
			double total = recharge - balance;
			System.out.println("合计：" + total);
			System.out.println("账户余额：" + user.attributeValue("balance"));
			// }
		}

	}
}
